﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_addNews : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["IsAuthorized"] = true;
        if (Request.QueryString["id"] != null && !Page.IsPostBack)
        {
            DataView dv = (DataView)SqlDataSourcexwgg.Select(DataSourceSelectArguments.Empty);
            if (dv.Table.Rows.Count != 0)
            {
                ddlLX.Text = dv[0]["xwClass"].ToString();//
                tbxTitle.Text = dv[0]["xwName"].ToString();
                Ckeditor.Text = dv[0]["xwContent"].ToString();
                
            }
            else
            {
                // 没有找到这个ID的文章
            }
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] == null)
        {
            SqlDataSourcexwgg.Insert();
            Response.Redirect("EditNews.aspx");
        }
        else
        {
            SqlDataSourcexwgg.Update();
            Response.Redirect("EditNews.aspx");
        }
    }
    protected void SqlDataSourcexwgg_Inserting(object sender, SqlDataSourceCommandEventArgs e)
    {
        e.Command.Parameters[0].Value = tbxTitle.Text;
        e.Command.Parameters[1].Value = "1";//Session["adminUserID"].ToString()
        e.Command.Parameters[2].Value = ddlLX.Text;
        e.Command.Parameters[3].Value = Ckeditor.Text;
        e.Command.Parameters[4].Value = DateTime.Now.ToString();
    }
    protected void SqlDataSourcexwgg_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        e.Command.Parameters[0].Value = Request.QueryString["id"];
    }
    
    protected void SqlDataSourcexwgg_Updating(object sender, SqlDataSourceCommandEventArgs e)
    {
        // @Param1, xwClass = @Param2, xwContent = @Param3 WHERE (xwID = @Param4)
        e.Command.Parameters[0].Value = tbxTitle.Text;
        e.Command.Parameters[1].Value = ddlLX.Text;
        e.Command.Parameters[2].Value =  Ckeditor.Text;
        e.Command.Parameters[3].Value = Request.QueryString["id"].ToString();
      
    }
}